<template>
  <div class="xtx-form">
    <div class="xtx-form-item">
      <div class="field">
        <i class="icon iconfont icon-user"></i>
        <input
          class="input"
          type="text"
          placeholder="请输入用户名"
          v-model="obj.account"
        />
      </div>
      <div class="error"></div>
    </div>
    <div class="xtx-form-item">
      <div class="field">
        <i class="icon iconfont icon-phone"></i>
        <input
          class="input"
          type="text"
          placeholder="请输入手机号"
          v-model="obj.mobile"
        />
      </div>
      <div class="error"></div>
    </div>
    <div class="xtx-form-item">
      <div class="field">
        <i class="icon iconfont icon-code"></i>
        <input
          class="input"
          type="text"
          placeholder="请输入验证码"
          v-model="obj.code"
        />
        <span class="code" @click="sendMsg">发送验证码</span>
      </div>
      <div class="error"></div>
    </div>
    <div class="xtx-form-item">
      <div class="field">
        <i class="icon iconfont icon-lock"></i>
        <input
          class="input"
          type="password"
          placeholder="请输入密码"
          v-model="obj.password"
        />
      </div>
      <div class="error"></div>
    </div>
    <div class="xtx-form-item">
      <div class="field">
        <i class="icon iconfont icon-lock"></i>
        <input class="input" type="password" placeholder="请确认密码" />
      </div>
      <div class="error"></div>
    </div>
    <a href="javascript:;" class="submit" @click="submit">立即提交</a>
  </div>
</template>

<script>
// 引入api
import { perfect, sendMsg } from "@/utils/Api/Login";
export default {
  props: ["openId"],
  data() {
    return {
      obj: {
        unionId: this.openId,
        account: "",
        mobile: "",
        code: "123456",
        password: "",
      },
    };
  },
  methods: {
    // 点击获取验证码
    sendMsg() {
      let obj = {
        mobile: this.obj.mobile,
        unionId: this.openId,
        source: 1,
      };
      // 请求接口
      sendMsg(obj)
        .then((res) => {
          this.$message({
            text: "发送验证码成功",
            type: "success",
          });
        })
        .catch((err) => {
          if (err.response.data.code == "17008") {
            this.$message({
              text: "发送验证码成功",
              type: "success",
            });
          }
        });
    },
    // 点击提交完善信息
    submit() {
      perfect(this.obj)
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          if (err.response.data.code == "17002") {
            this.$message({
              text: "用户名已存在",
              type: "error",
            });
          }
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.code {
  position: absolute;
  right: 0;
  top: 0;
  line-height: 50px;
  width: 80px;
  color: #999;
  &:hover {
    cursor: pointer;
  }
}
// 表单
.xtx-form {
  padding: 50px 0;
  &-item {
    display: flex;
    align-items: center;
    width: 700px;
    margin: 0 auto;
    padding-bottom: 25px;
    .label {
      width: 180px;
      padding-right: 10px;
      text-align: right;
      color: #999;
      ~ .field {
        margin-left: 0;
      }
    }
    .field {
      width: 320px;
      height: 50px;
      position: relative;
      margin-left: 190px;
      .icon {
        position: absolute;
        left: 0;
        top: 0;
        width: 40px;
        height: 50px;
        text-align: center;
        line-height: 50px;
        color: #999;
        ~ .input {
          padding-left: 40px;
        }
      }
      .input {
        border: 1px solid #e4e4e4;
        width: 320px;
        height: 50px;
        line-height: 50px;
        padding: 0 10px;
        &.err {
          border-color: red;
        }
        &:focus,
        &:active {
          border-color: #27bb9a;
        }
      }
    }
    .error {
      width: 180px;
      padding-left: 10px;
      color: red;
    }
  }
  .submit {
    width: 320px;
    height: 50px;
    border-radius: 4px;
    background: #27bb9a;
    height: 50px;
    line-height: 50px;
    text-align: center;
    font-size: 16px;
    color: #fff;
    display: block;
    margin: 0 auto;
  }
}
</style>
